package sebastiankerckhof.math;

import java.io.Serializable;


public class Vector3f extends Tuple3f implements Serializable
{
	
		public static final Vector3f ZERO = new Vector3f();
	
	
    /**
     * Constructs and initializes a Vector3f to (0,0,0).
     */

    public Vector3f()
    {
    }


    /**
     * Constructs and initializes a Vector3f from the specified xyz coordinates.
     * @param x
     * @param y
     * @param z
     */

    public Vector3f(float x, float y, float z)
    {
        super(x, y, z);
    }


    /**
     * Constructs and initializes a Vector3f from the specified Vector3f
     * @param v
     */

    public Vector3f(Vector3f v)
    {
        super(v);
    }


    /**
     * Constructs and initializes a Vector3f from the specified Tuple3f.
     * @param t
     */

    public Vector3f(Tuple3f t)
    {
        super(t);
    }


    /**
     * Constructs and initializes a Vector3f from the array of length 3.
     * @param v
     */

    public Vector3f(float v[])
    {
        super(v);
    }

    public static Vector3f getZero(){
    	return new Vector3f(0,0,0);
    }
    
    public Vector3f negative(){
    	return multiply(-1);
    }

    public Vector3f subtract(Vector3f o){ return minus(o); }
    public Vector3f minus(Vector3f o) {
	    return new Vector3f(this.x - o.x, this.y - o.y, this.z - o.z);
    }
    
    public Vector3f add(Vector3f o){ return plus(o); }
    public Vector3f plus(Vector3f o) {
	    return new Vector3f(this.x + o.x, this.y + o.y, this.z + o.z);
    }
    
    public Vector3f multiply(int i){return multiply((float) i);}
    public Vector3f multiply(double i){return multiply((float)i);}
    public Vector3f multiply(float i) {
	    return new Vector3f(this.x * i, this.y * i, this.z *i);
    }
    
    public float length(){
    	return (float) Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
    }
   
    
    /** if cartesian */
    public float dotProduct(Vector3f v){
    	return this.x * v.x + this.y *v.y + this.z * v.z;
    }
    
    /** if cartesian */
    public Vector3f crossProduct(Vector3f v){
    	return new Vector3f(this.y * v.z - this.z * v.y, this.z * v.x - this.x * v.z, this.x * v.y - this.y * v.x);
    }
    
    
    public Vector3f scale(float i){return multiply((float) i);}

    
    public Vector3f divide(int i){return divide((float) i);}
    public Vector3f divide(float i) {
	    return new Vector3f(this.x / i, this.y / i, this.z / i);
    }
    
    public Vector3f normalize(){
  		float length = this.length();
  		return new Vector3f(this.x/length, this.y/length, this.z/length);
  	}

}
